 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Jitter.LinearMath;

namespace Crystal.Mapping
{
    [Serializable]
    public struct MazePosition
    {
        public int X;        
        public int Z;
        public int Level;

        public MazePosition(int x, int z, int Level = 0)
        {
            this.X = x;
            this.Z = z;
            this.Level = Level;
        }

        public static implicit operator Vector3(MazePosition p)
        {
            return new Vector3(p.X, p.Level, p.Z);
        }
        public static implicit operator JVector(MazePosition p)
        {
            return new JVector(p.X, p.Level, p.Z);
        }

        public static implicit operator MazePosition(Vector3 p)
        {
            return new MazePosition((int)p.X, (int)p.Y,(int)p.Z);
        }
        public static implicit operator MazePosition(JVector p)
        {
            return new MazePosition((int)p.X, (int)p.Y, (int)p.Z);
        }

        public static MazePosition operator +(MazePosition one, MazePosition two)
        {
            return new MazePosition(one.X + two.X, one.Level, one.Z + two.Z);
        }
        public static MazePosition operator +(MazePosition one)
        {
            return new MazePosition(Math.Abs(one.X), Math.Abs(one.Level), Math.Abs(one.Z));
        }

        public static MazePosition operator -(MazePosition one, MazePosition two)
        {
            return new MazePosition(one.X - two.X, one.Level, one.Z - two.Z);
        }
        public static MazePosition operator -(MazePosition one)
        {
            return new MazePosition(Math.Abs(one.X) * -1, Math.Abs(one.Z) * -1);
        }

        public static bool operator ==(MazePosition one, MazePosition two)
        {
            return (one.X == two.X) && (one.Z == two.Z) && (one.Level == two.Level);
        }
        public static bool operator !=(MazePosition one, MazePosition two)
        {
            return (one.X != two.X) && (one.Z != two.Z) && (one.Level != two.Level);
        }

        public override string ToString()
        {
            return String.Format("X:{0}, Z:{1} L:{2}", this.X, this.Z, this.Level);
        }

        public static MazePosition Zero
        {
            get { return new MazePosition(0, 1, 0); }
        }
        public static MazePosition One
        {
            get {return new MazePosition(1, 1, 1);}
        }
    }
}
